Imports System.IO
Public Class DoEventsDemo

    Private Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button1.Click
        Try
            Dim dir As New DirectoryInfo("C:\WINDOWS\")
            Dim i As Integer = 1
            Dim max As Integer = dir.GetFiles("*.*").Length()
            ProgressBar1.Maximum = max
            Dim d As FileInfo
            For Each d In dir.GetFiles("*.*")
                Label1.Text = d.Name
                ProgressBar1.Value = i
                Dim j As Integer = Convert.ToInt32(Math.Floor(Convert.ToDouble(i * 100 / max)))
                Label2.Text = Convert.ToString(j) + "%"
                i = i + 1
                Application.DoEvents()
            Next
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try
    End Sub

End Class
